import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        //最大公约数（辗转相除法）
        Scanner scan= new Scanner(System.in);
        int a=scan.nextInt();
        int b=scan.nextInt();
        int c=a%b;
        while (c!=0){
            a=b;
            b=c;
            c=a%b;
        }
        System.out.println(b);
    }
    public static void main10(String[] args) {
        //判断一个数是不是素数（百度面试题）
        for (int i = 1; i <=100 ; i++) {
            int n=2;
            for ( ; n <Math.sqrt(i) ; n++) {
                if (i%n==0){
                    break;
                }

            }
            if(n>Math.sqrt(i)){
                System.out.println(i);
            }
        }
    }
    public static void main9(String[] args) {
        //查找n的二进制偶数位和奇数位
        int n=6;
        for (int i = 31; i >=1 ; i-=2) {
            System.out.print(((n>>i)&1)+" ");
        }
        System.out.println();
        for (int i = 30; i >=0 ; i-=2) {
            System.out.print(((n>>i)&1)+" ");
        }
    }
    public static void main8(String[] args) {
        Scanner scan= new Scanner(System.in);
        String pass=scan.nextLine();
        if(pass.equals("123") ){
            System.out.println(1);
        }
        else{
            System.out.println(0);
        }
    }
    public static void main7(String[] args) {
        //乘法口诀表
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <=i ; j++) {
                System.out.printf("%d*%d=%2d ",i,j,i*j);//右对齐打印
            }
            System.out.println();
        }
    }
    public static void main6(String[] args) {
        //打印x图形
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if((i==j)||(j+i==n-1)){
                    System.out.print("*");
                }else{
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
    public static void main5(String[] args) {
        //求自幂数(水仙数)
        for (int i = 1; i <= 999999; i++) {
            int count = 0;
            int tmp = i;
            int sum = 0;
            while (tmp != 0) {
                tmp = tmp / 10;
                count++;
            }
            tmp = i;
            while (tmp != 0) {
                sum += Math.pow(tmp % 10, count);
                tmp = tmp / 10;
            }
            if(sum==i)
                System.out.println(i);
        }
    }

    public static void main1(String[] args) {
        //查找n的二进制有多少个1
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int count = 0;
        for (int i = 0; i < 32; i++) {
            if (((n >> i) & 1) == 1) {
                count++;
            }
        }
        System.out.println(count);
    }

    public static void main2(String[] args) {
        //优化 查找查找n的二进制有多少个1
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int count = 0;
        while (n != 0) {
            if ((n & 1) == 1) {
                count++;
            }
            n = n >>> 1;//一定要是无符号右移
        }
        System.out.println(count);
    }

    public static void main3(String[] args) {
        //再优化
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int count = 0;
        while (n != 0) {
            n = n & (n - 1);
            count++;
        }
        System.out.println(count);
    }

    public static void main4(String[] args) {
        // 计算1-1/2+1/3-1/4+....+1/99-1/100
        double sum = 0.0;
        int flog = 1;
        for (int i = 1; i <= 100; i++) {
            sum = sum + 1.0 / i * flog;
            flog = -flog;
        }
        System.out.println(sum);

    }
}
